package com.pro_test.proservice.controller;


import com.pro_test.commonutils.R;
import com.pro_test.proservice.entity.UcenterMember;
import com.pro_test.proservice.entity.User;
import com.pro_test.proservice.service.UcenterMemberService;
import com.pro_test.proservice.service.UserService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 会员表 前端控制器
 * </p>
 *
 * @author Captain
 * @since 2022-03-10
 */
@RestController
@RequestMapping("/proservice/ucenter-member")
public class UcenterMemberController {

    @Autowired
    private UcenterMemberService userService;

    @ApiOperation(value = "查询所有用户")
    @GetMapping("findAll")
    public R findAllUser()
    {
        List<UcenterMember> list = userService.list(null);
        return R.ok().data("items",list);
    }

    @ApiOperation(value = "逻辑删除用户")
    @DeleteMapping("{id}")
    public R removeUser(@ApiParam(name = "id", value = "用户ID", required = true)
                        @PathVariable String id)
    {
        boolean flag = userService.removeById(id);
        if (flag)
        {
            return R.ok();
        }
        else
        {
            return R.error();
        }
    }

    @ApiOperation(value = "添加用户")
    @PostMapping("addUser")
    public R addUser(@RequestBody UcenterMember user)
    {
        boolean save = userService.save(user);
        if (save)
        {
            return R.ok();
        }
        else
        {
            return R.error();
        }
    }

    @ApiOperation(value = "查询用户")
    @GetMapping("getUser/{id}")
    public R getUser(@PathVariable String id)
    {
        UcenterMember user = userService.getById(id);
        return R.ok().data("user",user);
    }

    @ApiOperation(value = "修改用户")
    @PostMapping("updateUser")
    public R updateUser(@RequestBody UcenterMember user)
    {
        boolean flag = userService.updateById(user);
        if (flag)
        {
            return R.ok();
        }
        else
        {
            return R.error();
        }
    }
}

